# Protobuf stubs library.
#   These are utilities that mirror the behavior of internal Google code.

load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")

package(
    default_visibility = ["//:__subpackages__"],
)

cc_library(
    name = "lite",
    srcs = [
        "bytestream.cc",
        "common.cc",
        "int128.cc",
        "status.cc",
        "statusor.cc",
        "stringpiece.cc",
        "stringprintf.cc",
        "structurally_valid.cc",
        "strutil.cc",
        "time.cc",
    ],
    hdrs = [
        "bytestream.h",
        "callback.h",
        "casts.h",
        "common.h",
        "hash.h",
        "int128.h",
        "logging.h",
        "macros.h",
        "map_util.h",
        "mathutil.h",
        "mutex.h",
        "once.h",
        "platform_macros.h",
        "port.h",
        "status.h",
        "status_macros.h",
        "statusor.h",
        "stl_util.h",
        "stringpiece.h",
        "stringprintf.h",
        "strutil.h",
        "template_util.h",
        "time.h",
    ],
    copts = COPTS,
    include_prefix = "google/protobuf/stubs",
    linkopts = LINK_OPTS,
    deps = ["//src/google/protobuf:port_def"],
)

cc_library(
    name = "stubs",
    srcs = [
        "substitute.cc",
    ],
    hdrs = [
        "substitute.h",
    ],
    copts = COPTS,
    include_prefix = "google/protobuf/stubs",
    textual_hdrs = [
        "bytestream.h",
        "callback.h",
        "casts.h",
        "common.h",
        "hash.h",
        "int128.h",
        "logging.h",
        "macros.h",
        "map_util.h",
        "mathutil.h",
        "mutex.h",
        "once.h",
        "platform_macros.h",
        "port.h",
        "status.h",
        "status_macros.h",
        "statusor.h",
        "stl_util.h",
        "stringpiece.h",
        "stringprintf.h",
        "strutil.h",
        "template_util.h",
        "time.h",
    ],
    deps = [
        ":lite",
        "//src/google/protobuf:port_def",
    ],
)

cc_test(
    name = "stubs_test",
    srcs = [
        "bytestream_unittest.cc",
        "common_unittest.cc",
        "int128_unittest.cc",
        "status_test.cc",
        "statusor_test.cc",
        "stringpiece_unittest.cc",
        "stringprintf_unittest.cc",
        "structurally_valid_unittest.cc",
        "strutil_unittest.cc",
        "template_util_unittest.cc",
        "time_test.cc",
    ],
    copts = COPTS + select({
        "//build_defs:config_msvc": [],
        "//conditions:default": [
            "-Wno-deprecated-declarations",
        ],
    }),
    linkopts = LINK_OPTS,
    deps = [
        ":lite",
        ":stubs",
        "//src/google/protobuf/testing",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

################################################################################
# Distribution packaging
################################################################################

pkg_files(
    name = "dist_files",
    srcs = glob(["**/*"]),
    strip_prefix = strip_prefix.from_root(""),
    visibility = ["//src:__pkg__"],
)

filegroup(
    name = "test_srcs",
    srcs = glob([
        "*_test.cc",
        "*unittest.cc",
    ]),
    visibility = ["//pkg:__pkg__"],
)
